package main

import (
	"fmt"
	"os"
	codecs "sanguo/codec/cs"
	"sanguo/node/client/dispatcher"
	"sanguo/node/client/login"
	cs_msg "sanguo/protocol/cs/message"
	//"github.com/golang/protobuf/proto"
	"github.com/golang/protobuf/proto"
	"github.com/sniperHW/kendynet"
)

func main() {
	if len(os.Args) < 3 {
		fmt.Printf("usage leaveMap userID addr\n")
		return
	}

	userID := os.Args[1]
	addr := os.Args[2]

	login.Login(userID, addr, func(session kendynet.StreamSession, d *dispatcher.Dispatcher, msg *codecs.Message, err error) {
		if nil != err {
			fmt.Println(err)
		} else {
			gameLoginToC := msg.GetData().(*cs_msg.GameLoginToC)
			if gameLoginToC.GetCode() == cs_msg.EnumType_OK {
				req := &cs_msg.EnterMapToS{
					MapID: proto.Int32(1),
				}
				session.Send(codecs.NewMessage(uint16(0), req))

				d.Register(&cs_msg.LeaveMapToC{}, true, func(args []interface{}) {
					fmt.Println("leaveMap")
					resp := args[1].(*codecs.Message).GetData().(*cs_msg.LeaveMapToC)
					fmt.Println(resp)
				})

				d.Register(&cs_msg.EnterMapToC{}, true, func(args []interface{}) {
					fmt.Println("enterMap")
					resp := args[1].(*codecs.Message).GetData().(*cs_msg.EnterMapToC)
					fmt.Println(resp)

					req := &cs_msg.LeaveMapToS{
						MapID: proto.Int32(1),
					}
					session.Send(codecs.NewMessage(uint16(0), req))
				})

				d.Register(&cs_msg.EnterSeeToC{}, true, func(args []interface{}) {
					fmt.Println("onEnterSee")
					resp := args[1].(*codecs.Message).GetData().(*cs_msg.EnterSeeToC)
					fmt.Println(resp)
				})

			}
		}
	})

	sigStop := make(chan bool)
	_, _ = <-sigStop
}
